package com.crud.generator.dto.response;

/**
 * 代码片段类型，对应原有的各类模板输出。
 */
public enum CodeSegmentType {
    ENTITY("entity", CodeSegmentCategory.BACKEND),
    MAPPER("mapper", CodeSegmentCategory.BACKEND),
    SERVICE("service", CodeSegmentCategory.BACKEND),
    CONTROLLER("controller", CodeSegmentCategory.BACKEND),
    APPLICATION("application", CodeSegmentCategory.CONFIGURATION),
    POM("pom", CodeSegmentCategory.CONFIGURATION),
    APPLICATION_YML("applicationYml", CodeSegmentCategory.CONFIGURATION),
    README("readme", CodeSegmentCategory.CONFIGURATION),
    REDIS_CONFIG("redisConfig", CodeSegmentCategory.CONFIGURATION),
    SECURITY_CONFIG("securityConfig", CodeSegmentCategory.CONFIGURATION),
    TENANT_SECURITY_PROPERTIES("tenantSecurityProperties", CodeSegmentCategory.CONFIGURATION),
    MYBATIS_TENANT_CONFIG("mybatisTenantConfig", CodeSegmentCategory.CONFIGURATION),
    JWT_TOKEN_PROVIDER("jwtTokenProvider", CodeSegmentCategory.BACKEND),
    JWT_AUTHENTICATION_FILTER("jwtAuthenticationFilter", CodeSegmentCategory.BACKEND),
    JWT_AUTHENTICATION_ENTRY_POINT("jwtAuthenticationEntryPoint", CodeSegmentCategory.BACKEND),
    TENANT_AUTHENTICATION_SERVICE("tenantAuthenticationService", CodeSegmentCategory.BACKEND),
    AUTH_CONTROLLER("authController", CodeSegmentCategory.BACKEND),
    TENANT_CONTEXT("tenantContext", CodeSegmentCategory.BACKEND),
    TENANT_FILTER("tenantFilter", CodeSegmentCategory.BACKEND),
    TENANT_LINE_HANDLER("tenantLineHandler", CodeSegmentCategory.BACKEND),
    FRONTEND_MAIN("frontendMain", CodeSegmentCategory.FRONTEND),
    FRONTEND_APP("frontendApp", CodeSegmentCategory.FRONTEND),
    FRONTEND_ROUTER("frontendRouter", CodeSegmentCategory.FRONTEND),
    FRONTEND_API_BASE("frontendApiBase", CodeSegmentCategory.FRONTEND),
    FRONTEND_API_REQUEST("frontendApiRequest", CodeSegmentCategory.FRONTEND),
    FRONTEND_API_AUTH("frontendApiAuth", CodeSegmentCategory.FRONTEND),
    FRONTEND_TYPES_API("frontendTypesApi", CodeSegmentCategory.FRONTEND),
    FRONTEND_TYPES_ENTITY("frontendTypesEntity", CodeSegmentCategory.FRONTEND),
    FRONTEND_STYLES_INDEX("frontendStylesIndex", CodeSegmentCategory.FRONTEND),
    FRONTEND_UTILS_FORMAT("frontendUtilsFormat", CodeSegmentCategory.FRONTEND),
    FRONTEND_VIEW_DASHBOARD("frontendViewDashboard", CodeSegmentCategory.FRONTEND),
    FRONTEND_VIEW_ENTITY("frontendViewEntity", CodeSegmentCategory.FRONTEND),
    FRONTEND_VIEW_LOGIN("frontendViewLogin", CodeSegmentCategory.FRONTEND),
    FRONTEND_COMPONENT_ENTITY_MANAGER("frontendComponentEntityManager", CodeSegmentCategory.FRONTEND),
    FRONTEND_STORE_AUTH("frontendStoreAuth", CodeSegmentCategory.FRONTEND),
    FRONTEND_ENTITIES("frontendEntities", CodeSegmentCategory.FRONTEND),
    FRONTEND_PACKAGE("frontendPackage", CodeSegmentCategory.FRONTEND),
    FRONTEND_README("frontendReadme", CodeSegmentCategory.FRONTEND);

    private final String key;
    private final CodeSegmentCategory category;

    CodeSegmentType(String key, CodeSegmentCategory category) {
        this.key = key;
        this.category = category;
    }

    public String getKey() {
        return key;
    }

    public CodeSegmentCategory getCategory() {
        return category;
    }

    public static CodeSegmentType fromKey(String key) {
        for (CodeSegmentType type : CodeSegmentType.values()) {
            if (type.key.equals(key)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的代码片段类型: " + key);
    }
}
